package com.atwisdom.star.controller;

import com.atwisdom.star.common.vo.ResultInfo;
import com.atwisdom.star.core.dao.pojo.functionClass.Documents;
import com.atwisdom.star.docs.business.Impl.DocsBslServiceImpl;
import com.atwisdom.star.exception.pojo.BusinessException;
import com.atwisdom.star.log.aop.StarAnnotation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/docs")
public class DocsController {
    private final DocsBslServiceImpl docsBslService;
    public DocsController(DocsBslServiceImpl docsBslService) {
        this.docsBslService = docsBslService;
    }

    /**
     *
     * @param files 接收参数据
     * @return 返回结果
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/uploadFiles")
    public ResultInfo<?> uploadFiles(@RequestParam MultipartFile[] files) throws BusinessException {
        return docsBslService.uploadFiles(files);
    }

    /**
     *
     * @param file 接收参数据
     * @return 返回结果
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/uploadFile")
    public ResultInfo<?> uploadFile(@RequestParam MultipartFile file, @RequestParam String id) throws BusinessException {
        return docsBslService.uploadFile(file, id);
    }

    /**
     *
     * @param documents 接收参数据
     * @return 返回结果
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/downloadFile")
    public ResultInfo<?> downloadFile(@RequestBody Documents documents) throws BusinessException {
        return docsBslService.downloadFile( documents);
    }

    /**
     *
     * @param param 接收参数据
     * @return 返回结果
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/downloadFileById")
    public ResultInfo<?> downloadFileById(@RequestBody Map<String,String> param) throws BusinessException {
        return docsBslService.downloadFileById(param.get("id"));
    }

    /**
     *
     * @param documents 接收参数据
     * @return 返回结果
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/deleteFile")
    public ResultInfo<?> deleteFile(@RequestBody Documents documents) throws BusinessException {
        return docsBslService.deleteFile(documents);
    }
    /**
     *
     * @param param 接收参数据
     * @return 返回结果
     * @throws BusinessException  异常
     */
    @StarAnnotation
    @PostMapping(value = "/deleteFileById")
    public ResultInfo<?> deleteFileById(@RequestBody Map<String,String> param) throws BusinessException {
        return docsBslService.deleteFileById(param.get("id"));
    }
}
